<!DOCTYPE HTML>
<html>
	<head>
		<title>拖拽</title>
		<meta charset="utf-8">
		<style>
			#div1{
				width:200px;
				height:200px;
				background: red;
				position: absolute;
			}

		</style>
		<script>
			window.onload=function(){
				var oDiv=document.getElementById('div1');
				var disx=0;
				var disy=0;
				oDiv.onmousedown=function(ev){
					var oEvent=ev||event;
					disx=oEvent.clientX-oDiv.offsetLeft;
					disy=oEvent.clientY-oDiv.offsetTop;
					if(oDiv.setCapture)
					{
						oDiv.onmousemove=onMousemove;
						oDiv.onmouseup=onMouseup(oDiv);
					}
					else
					{
						document.onmousemove=onMousemove;
						document.onmouseup=onMouseup;
					}
					return false;
				};
			function onMousemove(ev)
			{
				var oEvent=ev||event;
				var l=oEvent.clientX-disx;
			    var t=oEvent.clientY-disy;
				oDiv.style.left=l+'px';
				oDiv.style.top=t+'px';
			}
			function onMouseup()
			{
				this.onmousemove=null;
				this.onmouseup=null;
				if(oDiv.releaseCapture)
				{oDiv.releaseCapture();
				}
			}
			}
		</script>
	</head>
	<body>
		<div id="div1">
		</div>
	</body>
</html>